
<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Controlling Syntax Coloring &#8212; Leo 6.7.2 documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="_static/classic.css" />
    <link rel="stylesheet" type="text/css" href="_static/custom.css" />
    
    <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
    <script src="_static/jquery.js"></script>
    <script src="_static/underscore.js"></script>
    <script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="_static/doctools.js"></script>
    <script src="_static/sphinx_highlight.js"></script>
    
    <script src="_static/sidebar.js"></script>
    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Writing Plugins" href="writingPlugins.html" />
    <link rel="prev" title="Advanced Topics" href="intermediatetopics.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="writingPlugins.html" title="Writing Plugins"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="intermediatetopics.html" title="Advanced Topics"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="leo_toc.html">Leo 6.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="intermediatetopics.html" accesskey="U">Advanced Topics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Controlling Syntax Coloring</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="controlling-syntax-coloring">
<h1>Controlling Syntax Coloring<a class="headerlink" href="#controlling-syntax-coloring" title="Permalink to this heading">¶</a></h1>
<p>This chapter discusses the settings to control Leo’s syntax colorer. This chapter also discusses how to extend Leo’s colorizer by creating xml language descriptions files and corresponding Python files. <strong>Important</strong>: this material is for those who want to support Leo’s colorizing code. To use Leo’s colorizers you only need to know about syntax-coloring settings.</p>
<div class="contents local topic" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#settings-for-syntax-coloring" id="id1">Settings for syntax coloring</a></p>
<ul>
<li><p><a class="reference internal" href="#color-settings" id="id2">Color settings</a></p></li>
<li><p><a class="reference internal" href="#font-settings" id="id3">Font settings</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#files" id="id4">Files</a></p></li>
<li><p><a class="reference internal" href="#the-colorizer-s-inner-loop" id="id5">The colorizer’s inner loop</a></p></li>
<li><p><a class="reference internal" href="#format-of-colorizer-control-files" id="id6">Format of colorizer control files</a></p>
<ul>
<li><p><a class="reference internal" href="#ruleset-names" id="id7">Ruleset names</a></p></li>
<li><p><a class="reference internal" href="#x-properties" id="id8">x.properties</a></p></li>
<li><p><a class="reference internal" href="#attribute-dictionaries-and-x-attributesdictdict" id="id9">Attribute dictionaries and x.attributesDictDict</a></p></li>
<li><p><a class="reference internal" href="#keyword-dictionaries-and-x-keywordsdictdict" id="id10">Keyword dictionaries and x.keywordsDictDict</a></p></li>
<li><p><a class="reference internal" href="#rules-rules-dictionaries-and-x-rulesdictdict" id="id11">Rules, rules dictionaries and x.rulesDictDict</a></p></li>
<li><p><a class="reference internal" href="#x-importdict-and-imported-versus-delegated-rulesets" id="id12">x.importDict and imported versus delegated rulesets</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#rule-methods" id="id13">Rule methods</a></p>
<ul>
<li><p><a class="reference internal" href="#arguments-to-rule-methods" id="id14">Arguments to rule methods</a></p></li>
<li><p><a class="reference internal" href="#match-eol-span" id="id15">match_eol_span</a></p></li>
<li><p><a class="reference internal" href="#match-eol-span-regexp" id="id16">match_eol_span_regexp</a></p></li>
<li><p><a class="reference internal" href="#match-keywords" id="id17">match_keywords</a></p></li>
<li><p><a class="reference internal" href="#match-mark-following" id="id18">match_mark_following</a></p></li>
<li><p><a class="reference internal" href="#match-mark-previous" id="id19">match_mark_previous</a></p></li>
<li><p><a class="reference internal" href="#match-seq" id="id20">match_seq</a></p></li>
<li><p><a class="reference internal" href="#match-seq-regexp" id="id21">match_seq_regexp</a></p></li>
<li><p><a class="reference internal" href="#match-span" id="id22">match_span</a></p></li>
<li><p><a class="reference internal" href="#match-span-regexp" id="id23">match_span_regexp</a></p></li>
<li><p><a class="reference internal" href="#match-terminate" id="id24">match_terminate</a></p></li>
</ul>
</li>
</ul>
</div>
<section id="settings-for-syntax-coloring">
<h2><a class="toc-backref" href="#id1">Settings for syntax coloring</a><a class="headerlink" href="#settings-for-syntax-coloring" title="Permalink to this heading">¶</a></h2>
<p>This section discusses only those settings that affect syntax coloring. See <a class="reference external" href="customizing.html">Customizing Leo</a> for a general discussion of Leo’s settings.</p>
<section id="color-settings">
<h3><a class="toc-backref" href="#id2">Color settings</a><a class="headerlink" href="#color-settings" title="Permalink to this heading">¶</a></h3>
<p>To specify a color, say for comment1, for <em>all</em> languages, create an &#64;color node:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@color</span> <span class="n">comment1</span> <span class="o">=</span> <span class="n">blue</span>
</pre></div>
</div>
<p>To specify a color for a <strong>particular</strong> language, say Python, prepend the setting name
with the language name.  For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@color</span> <span class="n">python_comment1</span> <span class="o">=</span> <span class="n">pink</span>
</pre></div>
</div>
<p>Here are Leo’s legacy (jEdit-based) &#64;color settings:</p>
<blockquote>
<div><p>&#64;color comment1
&#64;color comment2
&#64;color comment3
&#64;color comment4
&#64;color doc-part
&#64;color function
&#64;color keyword1
&#64;color keyword2
&#64;color keyword3
&#64;color keyword4
&#64;color keyword5
&#64;color label
&#64;color leo-keyword
&#64;color link
&#64;color literal1
&#64;color literal2
&#64;color literal3
&#64;color literal4
&#64;color markup
&#64;color name
&#64;color name-brackets
&#64;color null
&#64;color operator
&#64;color show-invisibles-space
&#64;color tab
&#64;color trailing-whitespace
&#64;color url</p>
</div></blockquote>
<p>In addition, the pygments colorizer uses these settings:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>@color comment
@color comment.hashbang
@color comment.multiline
@color comment.preproc
@color comment.single
@color comment.special
@color error
@color generic
@color generic.deleted
@color generic.emph
@color generic.error
@color generic.heading
@color generic.inserted
@color generic.output
@color generic.prompt
@color generic.strong
@color generic.subheading
@color generic.traceback
@color keyword
@color keyword.constant
@color keyword.declaration
@color keyword.namespace
@color keyword.pseudo
@color keyword.reserved
@color keyword.type
@color literal
@color literal.date
@color name.attribute
@color name.builtin
@color name.builtin.pseudo
@color name.class
@color name.constant
@color name.decorator
@color name.entity
@color name.exception
@color name.function
@color name.function.magic
@color name.label
@color name.namespace
@color name.other
@color name.pygments
@color name.tag
@color name.variable
@color name.variable.class
@color name.variable.global
@color name.variable.instance
@color name.variable.magic
@color number
@color number.bin
@color number.float
@color number.hex
@color number.integer
@color number.integer.long
@color number.oct
@color operator.word
@color other
@color punctuation
@color string
@color string.affix
@color string.backtick
@color string.char
@color string.delimiter
@color string.doc
@color string.double
@color string.escape
@color string.heredoc
@color string.interpol
@color string.other
@color string.regex
@color string.single
@color string.symbol
@color whitespace
@color xt
</pre></div>
</div>
<p><strong>Note</strong>: all &#64;color settings may optionally end with the _color suffix.</p>
</section>
<section id="font-settings">
<h3><a class="toc-backref" href="#id3">Font settings</a><a class="headerlink" href="#font-settings" title="Permalink to this heading">¶</a></h3>
<p>To specify a font, say for keyword_font, to be used as the default font for <strong>all</strong> languages, put the following in the body text of an &#64;font node in leoSettings.leo:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># keyword_font_family = None</span>
<span class="n">keyword_font_size</span> <span class="o">=</span> <span class="mi">16</span>
<span class="n">keyword_font_slant</span> <span class="o">=</span> <span class="n">roman</span>
    <span class="c1"># roman, italic</span>
<span class="n">keyword_font_weight</span> <span class="o">=</span> <span class="n">bold</span>
    <span class="c1"># normal, bold</span>
</pre></div>
</div>
<p>Comments are allowed and undefined settings are set to reasonable defaults. At present, comments can not follow a setting: comments must start a line.</p>
<p>You can specify per-language settings by preceding the settings names by a prefix x. Such settings affect only colorizing for language x (i.e., all the modes in modes/x.py when using the new colorizer). For example, to specify a font for php (only), put the following in the body text of an &#64;font node in leoSettings.leo:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># php_keyword_font_family = None</span>
<span class="n">php_keyword_font_size</span> <span class="o">=</span> <span class="mi">16</span>
<span class="n">php_keyword_font_slant</span> <span class="o">=</span> <span class="n">roman</span>
    <span class="c1"># roman, italic</span>
<span class="n">php_keyword_font_weight</span> <span class="o">=</span> <span class="n">bold</span>
    <span class="c1"># normal, bold</span>
</pre></div>
</div>
</section>
</section>
<section id="files">
<h2><a class="toc-backref" href="#id4">Files</a><a class="headerlink" href="#files" title="Permalink to this heading">¶</a></h2>
<p>The <a class="reference external" href="http://www.jedit.org/">jEdit</a> editor drives its syntax colorer using xml <strong>language description files.</strong> Rather than using the xml language description files directly, Leo uses Python <strong>colorer control files</strong>, created automatically from the xml files by a script called jEdit2Py.  All these files reside in the leo/modes directory.</p>
<p>These Python files contain all the information in the jEdit’s xml files, so we can (loosely) speak of modes, rulesets, rules, properties and attributes in the Python colorer control files. Later sections of this documentation will make this loose correspondence exact.</p>
<p>Each xml file describes one <strong>colorizing mode</strong>. A mode consists of one or more <strong>rulesets</strong>, and each ruleset consists of a list of <strong>colorizing rules</strong>. In addition, modes, rulesets and rules may have associated <strong>properties</strong> and <strong>attributes</strong>. Various rules may specify that the colorizer uses another ruleset (either in the same mode or another mode).</p>
<p><strong>Important</strong>: jEdit’s xml language description files contain no explicit &lt;RULE&gt; elements Rules are simply sub-elements of an enclosing &lt;RULES&gt; element. The element indicates the kind of rule that is specified, for example, &lt;SPAN&gt;, &lt;SEQ&gt;, etc. By the term <strong>rule element</strong> we shall mean any sub-element of the &lt;RULES&gt; element.</p>
<p><strong>Important</strong>: throughout this documentation, <strong>x.py</strong> will refer to the Python colorer for language x, and <strong>x.xml</strong> will refer to the corresponding xml language-description file.</p>
<p>Using Python colorer control files has the following advantages:</p>
<ul class="simple">
<li><p>Running jEdit2Py need only be done when x.xml changes, and the speed of the xml parser in jEdit2Py does not affect the speed of Leo’s colorizer in any way. Moreover, the jEdit2Py script can contain debugging traces and checks.</p></li>
<li><p>Colorer control files are valid .py files, so all of Python’s import optimizations work as usual. In particular, all the data in colorer control files is immediately accessible to Leo’s colorer.</p></li>
<li><p>Colorer control files are easier for humans to understand and modify than the equivalent xml file. Furthermore, it is easy to insert debugging information into Python colorer control files.</p></li>
<li><p>It is easy to modify the Python colorer control files ‘by hand’ without changing the corresponding xml file. In particular, it would be easy to define entirely new kinds of pattern-matching rules in Python merely by creating functions in a colorer control file.</p></li>
</ul>
</section>
<section id="the-colorizer-s-inner-loop">
<h2><a class="toc-backref" href="#id5">The colorizer’s inner loop</a><a class="headerlink" href="#the-colorizer-s-inner-loop" title="Permalink to this heading">¶</a></h2>
<p>When Leo’s syntax colorer sees the <a class="reference external" href="mailto:'&#37;&#52;&#48;language">‘<span>&#64;</span>language</a> x’ directive, it will import x.py from Leo’s modes folder. The colorer can then access any module-level object obj in x.py as x.obj.</p>
<p>Colorizer control files contain <strong>rules functions</strong> corresponding to rule elements in x.xml. The colorizer can call these functions as if they were members of the colorizer class by passing ‘self’ as the first argument of these functions. I call these rules <em>functions</em> to distinguish them from the corresponding <strong>rules methods</strong> which are actual methods of the colorizer class. Rules <em>functions</em> merely call corresponding rules <em>methods</em>. Indeed, rules functions are simply a way of binding values to keyword arguments of rules methods. These keywords arguments correspond to the xml attributes of rule elements in x.xml.</p>
<p>The colorizer calls rules functions until one matches, at which point a range of text gets colored and the process repeats. The inner loop of the colorizer is this code:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">rulesDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">],[]):</span>
    <span class="n">n</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">i</span> <span class="o">+=</span> <span class="n">n</span> <span class="p">;</span> <span class="k">break</span>
    <span class="k">else</span><span class="p">:</span> <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
</pre></div>
</div>
<ul class="simple">
<li><p>rulesDict is a dictionary whose keys are rulesets and whose values are ruleset dictionaries.
Ruleset dictionaries have keys that are single characters and whose values are
the list of rules that can start with that character.</p></li>
<li><p>s is the full text to be colorized.</p></li>
<li><p>i is the position within s is to be colorized.</p></li>
</ul>
<p>Rules methods (and functions) return n &gt; 0 if they match, and n == 0 if they fail.</p>
</section>
<section id="format-of-colorizer-control-files">
<h2><a class="toc-backref" href="#id6">Format of colorizer control files</a><a class="headerlink" href="#format-of-colorizer-control-files" title="Permalink to this heading">¶</a></h2>
<p>The following sections describe the top-level data in leo/modes/x.py.  This data is used by Leo’s Legacy (jEdit-based) colorizer. Leo’s pygments syntax colorizer does not use these files.</p>
<section id="ruleset-names">
<h3><a class="toc-backref" href="#id7">Ruleset names</a><a class="headerlink" href="#ruleset-names" title="Permalink to this heading">¶</a></h3>
<p>A <strong>ruleset name</strong> is a Python string having the form ‘x_setname’, where setname is the value of the SET attribute of the &lt;RULES&gt; element in x.xml. For example, the ruleset name of the ruleset whose SET attribute is JAVASCRIPT in php.xml is ‘php_JAVASCRIPT’. <strong>Important</strong>: by convention, the ruleset name of the default &lt;RULES&gt; element is ‘x_main’; note that default &lt;RULES&gt; element have no SET attributes.</p>
<p>The colorizer uses ruleset names to gain access to all data structures in x.py. To anticipate a bit, ruleset names are keys into two standard dictionaries, x.rulesDict and x.keywordsDictDict, from which the colorizer can get all other information in x.py:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># The rules list for the &#39;JAVASCRIPT&#39; ruleset in php.xml.</span>
<span class="n">rules</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">rulesDict</span><span class="p">(</span><span class="s1">&#39;php_JAVASCRIPT&#39;</span><span class="p">)</span>

<span class="c1"># The keywords dict for the &#39;JAVASCRIPT&#39; ruleset in php.xml.</span>
<span class="n">keywordsDict</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">keywordsDictDict</span><span class="p">(</span><span class="s1">&#39;php_JAVASCRIPT&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>In fact, ruleset names (and x.rulesDict and x.keywordsDictDict) are the <strong>only</strong> names that the colorizer needs to know in order to access all information in x.py.</p>
</section>
<section id="x-properties">
<h3><a class="toc-backref" href="#id8">x.properties</a><a class="headerlink" href="#x-properties" title="Permalink to this heading">¶</a></h3>
<p><strong>x.properties</strong> is a Python dictionary corresponding to the &lt;PROPS&gt; element in x.xml. Keys are property names; values are strings, namely the contents of &lt;PROPERTY&gt; elements in x.xml. x.properties contains properties for the entire mode. That is, only modes have &lt;PROPS&gt; elements. For example, here is x.properties in php.py:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># properties for mode php.xml</span>
<span class="n">properties</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;commentEnd&quot;</span><span class="p">:</span> <span class="s2">&quot;--&gt;&quot;</span><span class="p">,</span>
    <span class="s2">&quot;commentStart&quot;</span><span class="p">:</span> <span class="s2">&quot;&lt;!--&quot;</span><span class="p">,</span>
    <span class="s2">&quot;indentCloseBrackets&quot;</span><span class="p">:</span> <span class="s2">&quot;}&quot;</span><span class="p">,</span>
    <span class="s2">&quot;indentOpenBrackets&quot;</span><span class="p">:</span> <span class="s2">&quot;{&quot;</span><span class="p">,</span>
    <span class="s2">&quot;lineUpClosingBracket&quot;</span><span class="p">:</span> <span class="s2">&quot;true&quot;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
</section>
<section id="attribute-dictionaries-and-x-attributesdictdict">
<h3><a class="toc-backref" href="#id9">Attribute dictionaries and x.attributesDictDict</a><a class="headerlink" href="#attribute-dictionaries-and-x-attributesdictdict" title="Permalink to this heading">¶</a></h3>
<p>x.py contains a <strong>attribute dictionary</strong> for each ruleset in x.xml. Keys are attribute names, values strings representing the values of the attributes. This dictionary is empty if a ruleset contains no attributes. The valid keys are:</p>
<ul class="simple">
<li><p>‘default’: the default token type.  ‘null’ is the default.</p></li>
<li><p>‘digit_re’: a regular expression.
Words matching this regular expression are colored with the digit token type.</p></li>
<li><p>‘ignore_case’: ‘true’ or ‘false’.  Default is ‘true’.</p></li>
<li><p>‘highlight_digits’: ‘true’ or ‘false’.  Default is ‘true’.</p></li>
<li><p>‘no_word_sep’: A list of characters treated as ‘alphabetic’ characters when matching keywords.</p></li>
</ul>
<p>For example, here is one attribute dictionary in php.py:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Attributes dict for php_javascript ruleset.</span>
<span class="n">php_javascript_attributes_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;default&quot;</span><span class="p">:</span> <span class="s2">&quot;MARKUP&quot;</span><span class="p">,</span>
    <span class="s2">&quot;digit_re&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
    <span class="s2">&quot;highlight_digits&quot;</span><span class="p">:</span> <span class="s2">&quot;true&quot;</span><span class="p">,</span>
    <span class="s2">&quot;ignore_case&quot;</span><span class="p">:</span> <span class="s2">&quot;true&quot;</span><span class="p">,</span>
    <span class="s2">&quot;no_word_sep&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>x.py also contains <strong>x.attributesDictDict</strong>. Keys are ruleset names, values are attribute dictionaries. Here is attributesDictDict for php.py:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Dictionary of attributes dictionaries for php mode.</span>
<span class="n">attributesDictDict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;php_javascript&quot;</span><span class="p">:</span> <span class="n">php_javascript_attributes_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_javascript_php&quot;</span><span class="p">:</span> <span class="n">php_javascript_php_attributes_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_main&quot;</span><span class="p">:</span> <span class="n">php_main_attributes_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_php&quot;</span><span class="p">:</span> <span class="n">php_php_attributes_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_php_literal&quot;</span><span class="p">:</span> <span class="n">php_php_literal_attributes_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_phpdoc&quot;</span><span class="p">:</span> <span class="n">php_phpdoc_attributes_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_tags&quot;</span><span class="p">:</span> <span class="n">php_tags_attributes_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_tags_literal&quot;</span><span class="p">:</span> <span class="n">php_tags_literal_attributes_dict</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p><strong>Note</strong>: The jEdit2Py script creates ‘friendly’ names for attribute dictionaries <em>solely</em> as an aid for people reading the code. Leo’s colorer uses only the name x.attributeDictDict; Leo’s colorer never uses the actual names of attribute dictionaries.</p>
</section>
<section id="keyword-dictionaries-and-x-keywordsdictdict">
<h3><a class="toc-backref" href="#id10">Keyword dictionaries and x.keywordsDictDict</a><a class="headerlink" href="#keyword-dictionaries-and-x-keywordsdictdict" title="Permalink to this heading">¶</a></h3>
<p>x.py contains a <strong>keyword dictionary</strong> for each ruleset in x.xml. x.py contains an empty keywords dictionary if a ruleset contains no &lt;KEYWORDS&gt; element.</p>
<p>Keys are strings representing keywords of the language describe by the mode. Values are strings representing syntactic categories, i.e. a TYPE attribute valid in x.xml, namely: COMMENT1, COMMENT2, COMMENT3, COMMENT4, FUNCTION, KEYWORD1, KEYWORD2, KEYWORD3, KEYWORD4, LABEL, LITERAL1, LITERAL2, LITERAL3, LITERAL4, MARKUP, NULL and OPERATOR.</p>
<p>For example, here (parts of) some keyword dictionaries in php.py:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Keywords dict for mode php::PHP</span>
<span class="n">php_PHP_keywords_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;COM_invoke&quot;</span><span class="p">:</span> <span class="s2">&quot;keyword2&quot;</span><span class="p">,</span>
    <span class="s2">&quot;COM_load&quot;</span><span class="p">:</span> <span class="s2">&quot;keyword2&quot;</span><span class="p">,</span>
    <span class="s2">&quot;__CLASS__&quot;</span><span class="p">:</span> <span class="s2">&quot;keyword3&quot;</span><span class="p">,</span>
    <span class="o">...</span>
    <span class="s2">&quot;abs&quot;</span><span class="p">:</span> <span class="s2">&quot;keyword2&quot;</span><span class="p">,</span>
    <span class="s2">&quot;abstract&quot;</span><span class="p">:</span> <span class="s2">&quot;keyword1&quot;</span><span class="p">,</span>
    <span class="s2">&quot;accept_connect&quot;</span><span class="p">:</span> <span class="s2">&quot;keyword2&quot;</span><span class="p">,</span>
    <span class="o">...</span>
<span class="p">}</span>

<span class="c1"># Keywords dict for mode php::JAVASCRIPT_PHP</span>
<span class="n">php_JAVASCRIPT_PHP_keywords_dict</span> <span class="o">=</span> <span class="p">{}</span>

<span class="c1"># Keywords dict for mode php::PHPDOC</span>
<span class="n">php_PHPDOC_keywords_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;@abstract&quot;</span><span class="p">:</span> <span class="s2">&quot;label&quot;</span><span class="p">,</span>
    <span class="s2">&quot;@access&quot;</span><span class="p">:</span> <span class="s2">&quot;label&quot;</span><span class="p">,</span>
    <span class="s2">&quot;@author&quot;</span><span class="p">:</span> <span class="s2">&quot;label&quot;</span><span class="p">,</span>
    <span class="o">...</span>
    <span class="s2">&quot;@var&quot;</span><span class="p">:</span> <span class="s2">&quot;label&quot;</span><span class="p">,</span>
    <span class="s2">&quot;@version&quot;</span><span class="p">:</span> <span class="s2">&quot;label&quot;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>x.py also contains <strong>x.keywordsDictDict</strong>. Keys are ruleset names, values are keywords dictionaries. Here is keywordsDictDict for php.py:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Dictionary of keywords dictionaries for php mode.</span>
<span class="n">keywordsDictDict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;php_javascript&quot;</span><span class="p">:</span> <span class="n">php_javascript_keywords_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_javascript_php&quot;</span><span class="p">:</span> <span class="n">php_javascript_php_keywords_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_main&quot;</span><span class="p">:</span> <span class="n">php_main_keywords_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_php&quot;</span><span class="p">:</span> <span class="n">php_php_keywords_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_php_literal&quot;</span><span class="p">:</span> <span class="n">php_php_literal_keywords_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_phpdoc&quot;</span><span class="p">:</span> <span class="n">php_phpdoc_keywords_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_tags&quot;</span><span class="p">:</span> <span class="n">php_tags_keywords_dict</span><span class="p">,</span>
    <span class="s2">&quot;php_tags_literal&quot;</span><span class="p">:</span> <span class="n">php_tags_literal_keywords_dict</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The colorizer can get the keywords dictionary for a ruleset as follows:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">keywordsDict</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">keywordsDictDict</span><span class="p">(</span><span class="n">rulesetName</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Note</strong>: The jEdit2Py script creates ‘friendly’ names for keyword dictionaries <em>solely</em> as an aid for people reading the code. Leo’s colorer uses only the name x.keywordsDictDict; Leo’s colorer never uses the actual names of keywords dictionaries such as php_PHPDOC_keywords_dict.</p>
</section>
<section id="rules-rules-dictionaries-and-x-rulesdictdict">
<h3><a class="toc-backref" href="#id11">Rules, rules dictionaries and x.rulesDictDict</a><a class="headerlink" href="#rules-rules-dictionaries-and-x-rulesdictdict" title="Permalink to this heading">¶</a></h3>
<p>x.py contains one <strong>rule function</strong> for every rule in every ruleset (&lt;RULES&gt; element) in x.xml. These rules have names rule1 through  ruleN, where N is the total number of rules in all rulesets in x.xml.</p>
<p>Each rules <em>function</em> merely calls a rules <em>method</em> in Leo’s colorizer. Which method gets called depends on the corresponding element in <cite>x.xml</cite>. For example, the first rule in php.xml is:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>&lt;SPAN TYPE=&quot;MARKUP&quot; DELEGATE=&quot;PHP&quot;&gt;
            &lt;BEGIN&gt;&amp;lt;?php&lt;/BEGIN&gt;
            &lt;END&gt;?&amp;gt;&lt;/END&gt;
    &lt;/SPAN&gt;
</pre></div>
</div>
<p>and the corresponding rule function is:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">php_rule0</span><span class="p">(</span><span class="n">colorer</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">colorer</span><span class="o">.</span><span class="n">match_span</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">kind</span><span class="o">=</span><span class="s2">&quot;markup&quot;</span><span class="p">,</span> <span class="n">begin</span><span class="o">=</span><span class="s2">&quot;&lt;?php&quot;</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">&quot;?&gt;&quot;</span><span class="p">,</span>
        <span class="n">at_line_start</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">at_whitespace_end</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">at_word_start</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="n">delegate</span><span class="o">=</span><span class="s2">&quot;PHP&quot;</span><span class="p">,</span><span class="n">exclude_match</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="n">no_escape</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">no_line_break</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">no_word_break</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p>php_rule0 calls colorer.match_span because the corresponding xml rule is a &lt;SPAN&gt; element.</p>
<p>For each ruleset, x.py also contains a <strong>rules dictionary</strong>, a Python dictionary whose keys are characters and whose values are all lists of rules functions that that can match the key. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Rules dict for phpdoc ruleset.</span>
<span class="n">rulesDict8</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;*&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule64</span><span class="p">,],</span>
    <span class="s2">&quot;0&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;1&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;2&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;3&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;4&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;5&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;6&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;7&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;8&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;9&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;&lt;&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule65</span><span class="p">,</span><span class="n">rule66</span><span class="p">,</span><span class="n">rule67</span><span class="p">,</span><span class="n">rule68</span><span class="p">,</span><span class="n">rule69</span><span class="p">,],</span>
    <span class="s2">&quot;@&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;A&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;B&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="o">...</span>
    <span class="s2">&quot;X&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;Y&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;Z&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;_&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;a&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
   <span class="o">...</span>
    <span class="s2">&quot;x&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;y&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;z&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule70</span><span class="p">,],</span>
    <span class="s2">&quot;{&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">rule63</span><span class="p">,],</span>
<span class="p">}</span>
</pre></div>
</div>
<p><strong>Note</strong>: The order of rules in each rules list is important; it should be the same as rules element in x.xml.</p>
<p>Finally, x.py contains <strong>x.rulesDictDict</strong>. Keys are ruleset names, values are rules dictionaries. The colorer can get the rules list for character ch as follows:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="bp">self</span><span class="o">.</span><span class="n">rulesDict</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">rulesDictDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">rulesetName</span><span class="p">)</span> <span class="c1"># When a mode is inited.</span>
<span class="o">...</span>
<span class="n">rules</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rulesDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ch</span><span class="p">,[])</span> <span class="c1"># In the main loop.</span>
</pre></div>
</div>
<p>For example, here is the rules dictionary for php.py:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># x.rulesDictDict for php mode.</span>
<span class="n">rulesDictDict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;php_javascript&quot;</span><span class="p">:</span> <span class="n">rulesDict6</span><span class="p">,</span>
    <span class="s2">&quot;php_javascript_php&quot;</span><span class="p">:</span> <span class="n">rulesDict7</span><span class="p">,</span>
    <span class="s2">&quot;php_main&quot;</span><span class="p">:</span> <span class="n">rulesDict1</span><span class="p">,</span>
    <span class="s2">&quot;php_php&quot;</span><span class="p">:</span> <span class="n">rulesDict4</span><span class="p">,</span>
    <span class="s2">&quot;php_php_literal&quot;</span><span class="p">:</span> <span class="n">rulesDict5</span><span class="p">,</span>
    <span class="s2">&quot;php_phpdoc&quot;</span><span class="p">:</span> <span class="n">rulesDict8</span><span class="p">,</span>
    <span class="s2">&quot;php_tags&quot;</span><span class="p">:</span> <span class="n">rulesDict2</span><span class="p">,</span>
    <span class="s2">&quot;php_tags_literal&quot;</span><span class="p">:</span> <span class="n">rulesDict3</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p><strong>Note</strong>: The jEdit2Py script creates ‘friendly’ names for rules lists <em>solely</em> as an aid for people reading the code. Leo’s colorer uses only the name x.rulesDictDict; Leo’s colorer never uses the actual names of rules lists such as rulesDict8, and Leo’s colorer never uses the actual names of rules functions such as rule64.</p>
</section>
<section id="x-importdict-and-imported-versus-delegated-rulesets">
<h3><a class="toc-backref" href="#id12">x.importDict and imported versus delegated rulesets</a><a class="headerlink" href="#x-importdict-and-imported-versus-delegated-rulesets" title="Permalink to this heading">¶</a></h3>
<p>x.importDict is a Python dictionary. Keys are ruleset names; values are a list of ruleset names. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Import dict for php mode.</span>
<span class="n">importDict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;php_javascript_php&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;javascript::main&quot;</span><span class="p">],</span>
<span class="p">}</span>
</pre></div>
</div>
<p>For any ruleset R whose ruleset name is N, x.importDict.get(N) is the list of rulesets names whose rulesets appear in a DELEGATE attribute of an &lt;IMPORT&gt; rule element in R’s ruleset. Such <strong>imported</strong> ruleset are copied to the end of the R’s rules list. Leo’s colorizer does this copying only once, when loading ruleset R for the first time.</p>
<p><strong>Note 1</strong>: Loading imported rulesets must be done at ‘run time’. It should definitely not be done by jEdit2Py at ‘compile time’; that would require running jEdit2Py on <em>all</em> .xml files whenever any such file changed.</p>
<p><strong>Note 2</strong>:  Multiple &lt;IMPORT&gt; rule elements in a single ruleset are allowed: delegated rules are copied to the end of N’s rules list in the order they appear in the ruleset.</p>
<p><strong>Note 3</strong>: The DELEGATE attribute of &lt;IMPORT&gt; elements is, in fact, completely separate from the DELEGATE attributes of other rules as discussed in <a class="reference internal" href="#arguments-to-rule-methods">Arguments to rule methods</a>. Indeed, the DELEGATE attribute of &lt;IMPORT&gt; elements creates entries in x.importDict, which in turn causes the colorizer to append the rules of the imported ruleset to the end of the present rules list. In contrast, the DELEGATE attributes of other rules sets the delegate argument to rules methods, which in tern causes the colorizer to recursively color the matched text with the <strong>delegated</strong> ruleset. In short:</p>
<ul class="simple">
<li><p>The rules of <strong>imported</strong> rulesets are appended to the end of another rules list; the rules of <strong>delegated</strong> rulesets never are.</p></li>
<li><p><strong>Imported</strong> ruleset names appear as the values of items in x.importDict; <strong>delegated</strong> ruleset names appear as delegate arguments to rule methods.</p></li>
</ul>
</section>
</section>
<section id="rule-methods">
<h2><a class="toc-backref" href="#id13">Rule methods</a><a class="headerlink" href="#rule-methods" title="Permalink to this heading">¶</a></h2>
<p>This section describes each rules method in Leo’s jEdit-based colorizer. Rules methods are called by rules functions in colorizer control file; they correspond directly to rules elements in jEdit’s language description files.</p>
<p>All rule methods attempt to match a pattern at a particular spot in a string. These methods all return True if the match succeeds.</p>
<section id="arguments-to-rule-methods">
<h3><a class="toc-backref" href="#id14">Arguments to rule methods</a><a class="headerlink" href="#arguments-to-rule-methods" title="Permalink to this heading">¶</a></h3>
<p>All rule methods take three required arguments and zero or more optional keyword arguments.</p>
<p>Here is a list of the required arguments and their meaning:</p>
<ul class="simple">
<li><p><strong>self</strong>: An instance of Leo’s colorizer.</p></li>
<li><p><strong>s</strong>: The string in which matches may be found.</p></li>
<li><p><strong>i</strong>: The location within the string at which the rule method looks for a match.</p></li>
</ul>
<p>Here is a list of all optional keyword arguments and their meaning:</p>
<ul class="simple">
<li><p><strong>at_line_start</strong>:
If True, a match will succeed only if i is at the start of a line.</p></li>
<li><p><strong>at_whitespace_end</strong>:
If True, the match will succeed only if i is at the first non-whitespace text in a line.</p></li>
<li><p><strong>at_word_start</strong>:
If True, the match will succeed only if i is at the beginning of a word.</p></li>
<li><p><strong>delegate</strong>:
If non-empty, the value of this argument is a <a class="reference internal" href="#ruleset-names">ruleset name</a>.
If the match succeeds, the matched text will be colored recursively with the indicate ruleset.</p></li>
<li><p><strong>exclude_match</strong>:
If True, the actual text that matched will not be colored.
The meaning of this argument varies slightly depending on whether one or two sequences are matched.
See the individual rule methods for details.</p></li>
<li><p><strong>kind</strong>: A string representing a class of tokens, i.e., one of:
‘comment1’, ‘comment2’, ‘comment3’, ‘comment4’, ‘function’,
‘keyword1’, ‘keyword2’, ‘keyword3’, ‘keyword4’,
‘label’, ‘literal1’, ‘literal2’, ‘literal3’, ‘literal4’,
‘markup’, ‘null’ and ‘operator’.</p></li>
<li><p><strong>no_escape</strong>:
If True, the ruleset’s escape character will have no effect before the end argument to match_span.
Otherwise, the presence of the escape character will cause that occurrence of the end string to be ignored.</p></li>
<li><p><strong>no_line_break</strong>:
If True, the match will not succeed across line breaks.</p></li>
<li><p><strong>no_word_break</strong>:
If True, the match will not cross word breaks.</p></li>
</ul>
<p>New in Leo 4.4.1 final: the regular expression rule matchers no longer get a hash_char argument
because such matchers are called only if the present search pattern starts with hash_char.</p>
</section>
<section id="match-eol-span">
<h3><a class="toc-backref" href="#id15">match_eol_span</a><a class="headerlink" href="#match-eol-span" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_eol_span</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">begin</span><span class="p">,</span>
    <span class="n">at_line_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_whitespace_end</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_word_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">delegate</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
    <span class="n">exclude_match</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span>
</pre></div>
</div>
<p>match_eol_span succeeds if s[i:].startswith(begin) and the at_line_start, at_whitespace_end and at_word_start conditions are all satisfied.</p>
<p>If successful, match_eol_span highlights from i to the end of the line with the color specified by kind. If the exclude_match argument is True, only the text before the matched text will be colored. The delegate argument, if present, specifies the ruleset to color the colored text.</p>
</section>
<section id="match-eol-span-regexp">
<h3><a class="toc-backref" href="#id16">match_eol_span_regexp</a><a class="headerlink" href="#match-eol-span-regexp" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_eol_span_regexp</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">regex</span><span class="p">,</span>
    <span class="n">at_line_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_whitespace_end</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_word_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">delegate</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
    <span class="n">exclude_match</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span>
</pre></div>
</div>
<p>match_eol_span_exp succeeds if:</p>
<ol class="arabic simple">
<li><p>The regular expression regex matches at s[i:], and</p></li>
<li><p>The at_line_start, at_whitespace_end and at_word_start conditions are all satisfied.</p></li>
</ol>
<p>If successful, match_eol_span_regexp  highlights from i to the end of the line. If the exclude_match argument is True, only the text before the matched text will be colored. The delegate argument, if present, specifies the ruleset to color the colored text.</p>
</section>
<section id="match-keywords">
<h3><a class="toc-backref" href="#id17">match_keywords</a><a class="headerlink" href="#match-keywords" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_keywords</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">):</span>
</pre></div>
</div>
<p>match_keywords succeeds if s[i:] starts with an identifier contained in the mode’s keywords dictionary d.</p>
<p>If successful, match_keywords colors the keyword. match_keywords does not take a kind keyword argument. Instead, the keyword is colored as specified by d.get(theKeyword).</p>
</section>
<section id="match-mark-following">
<h3><a class="toc-backref" href="#id18">match_mark_following</a><a class="headerlink" href="#match-mark-following" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_mark_following</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">pattern</span><span class="p">,</span>
    <span class="n">at_line_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_whitespace_end</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_word_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">exclude_match</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span>
</pre></div>
</div>
<p>match_mark_following succeeds if s[i:].startswith(pattern), and the at_line_start, at_whitespace_end and at_word_start conditions are all satisfied.</p>
<p>If successful, match_mark_following colors from i to the start of the next token with the color specified by kind. If the exclude_match argument is True, only the text after the matched text will be colored.</p>
</section>
<section id="match-mark-previous">
<h3><a class="toc-backref" href="#id19">match_mark_previous</a><a class="headerlink" href="#match-mark-previous" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_mark_previous</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">pattern</span><span class="p">,</span>
    <span class="n">at_line_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_whitespace_end</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_word_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">exclude_match</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span>
</pre></div>
</div>
<p>At present match_mark_previous does nothing (always returns 0).
Its use is deprecated.</p>
</section>
<section id="match-seq">
<h3><a class="toc-backref" href="#id20">match_seq</a><a class="headerlink" href="#match-seq" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_seq</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">seq</span><span class="p">,</span>
    <span class="n">at_line_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_whitespace_end</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_word_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">delegate</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">):</span>
</pre></div>
</div>
<p>match_seq succeeds if s[i:].startswith(seq) and the at_line_start, at_whitespace_end and at_word_start conditions are all satisfied.</p>
<p>If successful, match_seq highlights from i to the end of the sequence with the color specified by kind. The delegate argument, if present, specifies the ruleset to color the colored text.</p>
</section>
<section id="match-seq-regexp">
<h3><a class="toc-backref" href="#id21">match_seq_regexp</a><a class="headerlink" href="#match-seq-regexp" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_seq_regexp</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">regex</span><span class="p">,</span>
    <span class="n">at_line_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_whitespace_end</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_word_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">delegate</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">):</span>
</pre></div>
</div>
<p>match_seq succeeds if:</p>
<ol class="arabic simple">
<li><p>The regular expression regex matches at s[i:], and</p></li>
<li><p>The at_line_start, at_whitespace_end and at_word_start conditions are all satisfied.</p></li>
</ol>
<p>If successful, match_seq_regexp highlights from i to the end of the sequence with the color specified by kind. The delegate argument, if present, specifies the ruleset to color the colored text.</p>
</section>
<section id="match-span">
<h3><a class="toc-backref" href="#id22">match_span</a><a class="headerlink" href="#match-span" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_span</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">begin</span><span class="p">,</span><span class="n">end</span><span class="p">,</span>
    <span class="n">at_line_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_whitespace_end</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_word_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">exclude_match</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">delegate</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
    <span class="n">no_escape</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">no_line_break</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">no_word_break</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span>
</pre></div>
</div>
<p>match_span succeeds if there is an index j &gt; i such that s[:i].startswith(begin) and s[i:j].endswith(end) and the at_line_start, at_whitespace_end, at_word_start, no_escape, no_line_break and no_word_break conditions are all satisfied.</p>
<p>If successful, match_span highlights from s[i:j with the color specified by kind; but if the exclude_match argument is True, the begin and end text are not colored. The delegate argument, if present, specifies the ruleset to color the colored text.</p>
</section>
<section id="match-span-regexp">
<h3><a class="toc-backref" href="#id23">match_span_regexp</a><a class="headerlink" href="#match-span-regexp" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_span</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">regex</span><span class="p">,</span><span class="n">end</span><span class="p">,</span>
    <span class="n">at_line_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_whitespace_end</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">at_word_start</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">exclude_match</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">delegate</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
    <span class="n">no_escape</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">no_line_break</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">no_word_break</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span>
</pre></div>
</div>
<p>match_span_regex succeeds if:</p>
<ol class="arabic simple">
<li><p>The regular expression regex matches at s[i:],</p></li>
<li><p>There is an index j &gt; i such that s[i:j].endswith(end),</p></li>
<li><p>The at_line_start, at_whitespace_end, at_word_start,
no_escape, no_line_break and no_word_break conditions are all satisfied.</p></li>
</ol>
<p>If successful, match_span colors s[i:j], with the color specified by kind; but if the exclude_match argument is True, the begin and end text are not colored. The delegate argument, if present, specifies the ruleset to color the colored text.</p>
</section>
<section id="match-terminate">
<h3><a class="toc-backref" href="#id24">match_terminate</a><a class="headerlink" href="#match-terminate" title="Permalink to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">match_terminate</span> <span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">kind</span><span class="p">,</span><span class="n">at_char</span><span class="p">):</span>
</pre></div>
</div>
<p>match_terminate succeeds if s[i:] contains at least at_char more characters.</p>
<p>If successful, match_terminate colors at_char characters with the color specified by kind.</p>
</section>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="leo_toc.html">
              <img class="logo" src="_static/LeoLogo.svg" alt="Logo"/>
            </a></p>
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="intermediatetopics.html"
                          title="previous chapter">Advanced Topics</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="writingPlugins.html"
                          title="next chapter">Writing Plugins</a></p>
  </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>

      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="writingPlugins.html" title="Writing Plugins"
             >next</a> |</li>
        <li class="right" >
          <a href="intermediatetopics.html" title="Advanced Topics"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="leo_toc.html">Leo 6.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="intermediatetopics.html" >Advanced Topics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Controlling Syntax Coloring</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 1997-2023, Edward K. Ream.
      Last updated on February 28, 2023.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
    </div>
  </body>
</html>